package main

import (
	"database/sql"
	"fmt"
	"github.com/didi/gendry/builder"
	"github.com/didi/gendry/manager"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

func update(db *sql.DB) {
	where := map[string]interface{}{
		"score>":   0,
		"province": "fff",
		"city":     []string{"fff"},
	}

	data := map[string]interface{}{
		"addr":       "yichuan",
		"enrollment": time.Now().Format("2006-01-02"),
	}

	template, values, _ := builder.BuildUpdate("student", where, data)
	fmt.Println(template, values)

	res, err := db.Exec(template, values...)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(res.RowsAffected())
}

func main() {
	db, err := manager.New("test", "admin", "yicai127", "192.168.0.105").
		Set(manager.SetCharset("utf8")).
		Port(3306).
		Open(true)
	defer db.Close()
	if err != nil {
		panic(err)
		return
	}

	update(db)
}
